#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <arpa/inet.h>
#include <math.h>
#include "dnfs.h"
#include "common.h"

//标志了每个osd
typedef struct osd{
	CLIENT *cl;
	IP ip;
	pthread_mutex_t lock;
	struct osd *next;
} OSD;


typedef struct meta_cache{
	FILENAME path;
	pthread_mutex_t lock;
	int wcount;
	int rcount;
	char isdirty;//0 mean not dirty;1 means dirty
	uint64_t oldsize;
	uint64_t newsize;//用于write的过程中
	uint32_t o_chunknum;
	uint32_t n_chunknum;//用于write的过程中
	CHUNK_MEM **chunkarray;
	struct meta_cache *next, *pre;
} META_CACHE;

CLIENT * create_osd_handle(IP ipn);
OSD * get_osd(IP ipn);
int replace_clo(IP ipn, CLIENT *clo);
int init() ;
int getchunk(const void *buf, uint32_t buflen, META_CACHE *meta);
int insert_meta(META_CACHE *meta);
void free_meta(META_CACHE *meta);
int delete_meta(const char *path);
META_CACHE *find_meta(const char *);
int add_chunk(META_CACHE *, const CHUNK_MEM *, int);
void print_one_metacache(META_CACHE *);
void print_all_metacache();
//CLIENT * create_mds_handle(IP ipn);
int getcid(uint64_t);
int ask_newchunk(const char*, int, META_CACHE*);
int get_local_ip(uint32_t *);
